package com.ruoyi.common.core.page;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.Serializable;
import java.util.List;

/**
 * 表格分页数据对象
 *
 * @author ruoyi
 */
@Getter
@Setter
@ApiModel(value = "表格分页实体对象")
public class TableDataInfo<T> implements Serializable {
    private static final long serialVersionUID = 9163913814335676075L;

    /**
     * 总记录数
     */
    @ApiModelProperty(value = "总记录数")
    private long total;
    /**
     * 列表数据
     */
    @ApiModelProperty(value = "列表数据")
    private List<T> rows;
    /**
     * 消息状态码
     */
    @ApiModelProperty(value = "消息状态码")
    private int code;
    /**
     * 消息内容
     */
    @ApiModelProperty(value = "消息内容")
    private String msg;

    public TableDataInfo() {
    }


    public TableDataInfo(List<T> list, int total) {
        this.rows = list;
        this.total = total;
    }

    public TableDataInfo(long total, List<T> rows, int code, String msg) {
        this.total = total;
        this.rows = rows;
        this.code = code;
        this.msg = msg;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof TableDataInfo)) {
            return false;
        }
        TableDataInfo<?> that = (TableDataInfo<?>) o;
        return new EqualsBuilder().append(getTotal(), that.getTotal()).append(getCode(), that.getCode()).append(getRows(), that.getRows()).append(getMsg(), that.getMsg()).isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .append("total", total)
                .append("rows", rows)
                .append("code", code)
                .append("msg", msg)
                .toString();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(getTotal())
                .append(getRows())
                .append(getCode())
                .append(getMsg())
                .toHashCode();
    }
}
